package com.nd.qa.shareplate.service.impl;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nd.qa.shareplate.IDao.UserMapper;
import com.nd.qa.shareplate.common.CPResultCode;
import com.nd.qa.shareplate.model.User;
import com.nd.qa.shareplate.service.UserService;

@Service("com.nd.qa.shareplate.service.UserService")
public class UserServiceImpl implements UserService{

	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User queryByUserName(String userName) throws Exception {
		// TODO Auto-generated method stub
		return userMapper.queryByUserName(userName);
	}

	@Override
	public HashMap<String, Object> registerUser(User user) throws Exception {
		
		HashMap<String, Object> returnMap = new HashMap<String,Object>();
		try {
			userMapper.registerUser(user);
			returnMap.put("code", CPResultCode.CP0000);
		} catch (Exception e) {
			returnMap.put("code", CPResultCode.CP1001);
			returnMap.put("message", e);
		}
		return returnMap;
	}

	@Override
	public User queryByUserById(String userId) throws Exception {
		return userMapper.queryByUserById(userId);
	}

	@Override
	public void updateUser(User user) throws Exception {
		userMapper.updateUser(user);
	}
}
